﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/**
*@file       gamemsgprocdispath.cs
*@brief      game message dispatch
*
*@author     graywind
*@version    1.0.0.0
*@data       2012/01/04
*/

public partial class NetOperateListenDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateListen>
{
    public static new void OnDispatch(Operator p, Int32 session_id, IntPtr pMsgBuffer, UInt32 msgId, UInt32 msg_bytes, Int32 error_code)
    {
        if (error_code == 0)
        {
            System.Console.WriteLine("A New Session Connected!");
        }
        else
        {
            System.Console.WriteLine("Can Not Accept A New Session! Session:{0}   Error Code:{1}", session_id, error_code);
        }
    }
}

public partial class NetOperateConnectDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateConnect>
{
    public static new void OnDispatch(Operator p, Int32 session_id, IntPtr pMsgBuffer, UInt32 msgId, UInt32 msg_bytes, Int32 error_code)
    {
        if (error_code == 0)
        {
            System.Console.WriteLine("Connect To Server Success!");
        }
        else
        {
            System.Console.WriteLine("Can Not Connect To Server! Error Code:{0}", error_code);
        }
    }
}

public partial class NetOperateSendDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateSend>
{
    public static new void OnDispatch(Operator p, Int32 session_id, IntPtr pMsgBuffer, UInt32 msgId, UInt32 msg_bytes, Int32 error_code)
    {
        if (error_code != 0)
        {
            System.Console.WriteLine("Send Message Error! Error Code:{0}", error_code);
        }
    }
}

public partial class NetOperateReadDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateRead>
{
    public static new void OnDispatch(Operator p, Int32 session_id, IntPtr pMsgBuffer, UInt32 msgId, UInt32 msg_bytes, Int32 error_code)
    {
        if (error_code == 0)
        {
            ((IMessageOperator)p).StoreMessage(session_id, pMsgBuffer, msgId, msg_bytes);
        }
        else
        {
            System.Console.WriteLine("Read Message Error! Error Code:{0}", error_code);
        }
    }
}
